package com.cloudsigns.factorymanager2.project.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.adapter.GridAdapter;
import com.cloudsigns.factorymanager2.project.bean.ProductBean;
import com.cloudsigns.factorymanager2.project.bean.SurveyFeedBackForSizeBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2018/8/10.
 */

public class SurveyFeedBackForSizeAdapter extends BaseAdapter {
    private Activity context;
    private List<SurveyFeedBackForSizeBean> datas = new ArrayList<SurveyFeedBackForSizeBean>();
    private LayoutInflater inflater;
    private ItemClickListener itemClickListener;
    private String tag = "";


    public SurveyFeedBackForSizeAdapter(Activity context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;

    }

    //    EngineeringDailyFeedBackBean
    public void setData(List<SurveyFeedBackForSizeBean> list) {

        if (null != list) {
            this.datas.clear();
            this.datas.addAll(list);
        }

    }

    public void setItemClick(ItemClickListener clickListener) {
        this.itemClickListener = clickListener;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public SurveyFeedBackForSizeBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_survey_feedback_for_size, null);
            holder.tv_content = convertView.findViewById(R.id.tv_content);
            holder.tv_value = convertView.findViewById(R.id.tv_value);
            holder.gridView = convertView.findViewById(R.id.gridView);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SurveyFeedBackForSizeBean surveyFeedBackForSizeBean = datas.get(position);
        if (null != surveyFeedBackForSizeBean) {
            holder.tv_content.setText(surveyFeedBackForSizeBean.getContent());

            CommonEnum.SurveySizeType surveySizeType = surveyFeedBackForSizeBean.getSurveySizeType();
            if (null != surveySizeType) {
                if (surveySizeType == CommonEnum.SurveySizeType.normal) {
                    holder.tv_value.setText("宽" + surveyFeedBackForSizeBean.getWidth() + "/高" + surveyFeedBackForSizeBean.getHight() + "/转角"
                            + surveyFeedBackForSizeBean.getCorner() + "/高差" + surveyFeedBackForSizeBean.getHightDif());
                } else if (surveySizeType == CommonEnum.SurveySizeType.special) {
                    holder.tv_value.setText("宽" + surveyFeedBackForSizeBean.getSpecialWidth() + "/高" + surveyFeedBackForSizeBean.getSpecialHight() + "/弧长"
                            + surveyFeedBackForSizeBean.getArcLength() + "/弧高" + surveyFeedBackForSizeBean.getArcHight());
                }
            }
            List<String> imgUrlList = surveyFeedBackForSizeBean.getImgUrlList();
            if (null != imgUrlList && imgUrlList.size() > 0) {
                holder.gridView.setNumColumns(3);
                GridAdapter gridAdapter = new GridAdapter(context);
                gridAdapter.setData(imgUrlList);
                holder.gridView.setAdapter(gridAdapter);
            }


        }

        return convertView;
    }

    private class ViewHolder {
        private TextView tv_content;
        private TextView tv_value;
        private GridView gridView;

    }
}
